<template>
  <div>
    <Upload 
        ref="upload"
        action="/api/file/uploadExcel" 
        name="file"
        :data="uploadData"
        :show-upload-list="true"
        :before-upload="handleUpload"
        :on-format-error="handleFormatError"
        :on-success="handleSuccess"
        :on-error="handleError"
        :format="['xlsx','xls']">
        <Button type="info" icon="ios-cloud-upload-outline">导入</Button>
    </Upload>
  </div>
</template>
 
<script>
export default {
  name: 'batchUploadExecl',
  data() {
    return {
      uploadData: {
        fileName: ''
      }
    }
  },
  methods: {
    handleUpload(file) {
      this.uploadData.fileName = file.name
    },
    handleFormatError(file){
        this.$Notice.warning({
            title: '文件格式不正确',
            desc: '文件 ' + file.name + ' 格式不正确，请上传.xls,.xlsx文件。'
        })
    },
    handleSuccess(res,file){
        if(res.code === 200){
            this.dialoLead = false
            this.$Message.success(res.data)
            this._getBookList()
            this.$refs.upload.clearFiles()
        }
    },
    handleError(error,file){
        this.$Message.error("数据导入失败！")
    },
  }
}
</script>
 
<style scoped>
 
</style>